#include <EIKENV.H>

#include "MyWaitDlg.h"
#include "MyTimer.h"

#include "MyDataCenter.h"
#include <html\htmlcontrol.h>
extern CHtmlControl* gHtmlControl;
extern CMyDataCenter* iDataCenter;

MyWaitDlg::MyWaitDlg()
{
    iTimer = CMyTimer::NewL(this, 100);	
	iTimer->m_interval = 1000000;
}


  
MyWaitDlg::~MyWaitDlg()
{
	if(iTimer)
	{
		iTimer->Cancel();
		delete iTimer;
	}	
}

//delay, in second
void MyWaitDlg::Note(const TDesC& msg, int delay)
{
	CHtmlElement* itemcontainer = gHtmlControl->Element(_L("iNote"));
	if(itemcontainer == NULL)
		return;
	itemcontainer->SetProperty(KHStrInnerText, msg);
	itemcontainer->SetStyle(KHStrDisplay, KHStrVisible);	
	gHtmlControl->RefreshAndDraw();	
//	iDataCenter->LoadMemPage(iTest->iRichText1, "dialog", _L("note.xml"));
//    iTest->iRichText1->ReplaceMyField(_L("prompt"), msg, true);	    

	if(delay != 0){
		iTimer->Cancel();
		iTimer->m_interval = 1000000 * delay;
		iTimer->Activate();
	}
}

void MyWaitDlg::EndWait()
{
	iTimer->Cancel();	
		
	CHtmlElement* itemcontainer = gHtmlControl->Element(_L("iNote"));
	if(itemcontainer == NULL)
		return;
	itemcontainer->SetStyle(KHStrDisplay, KHStrNone);
	gHtmlControl->RefreshAndDraw();		
}


//确保在owner中的draw中，调用gif::DrawFrame.
void MyWaitDlg::OnTimer(CMyTimer* timer, int eventid, int extrapara)
{
	EndWait();
}
